<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/app.css" rel="stylesheet" />
		<style>
			.mui-preview-image.mui-fullscreen {
				position: fixed;
				z-index: 20;
				background-color: #000;
			}

			.mui-preview-header,
			.mui-preview-footer {
				position: absolute;
				width: 100%;
				left: 0;
				z-index: 10;
			}

			.mui-preview-header {
				height: 44px;
				top: 0;
			}

			.mui-preview-footer {
				height: 50px;
				bottom: 0px;
			}

			.mui-preview-header .mui-preview-indicator {
				display: block;
				line-height: 25px;
				color: #fff;
				text-align: center;
				margin: 15px auto 4;
				width: 70px;
				background-color: rgba(0, 0, 0, 0.4);
				border-radius: 12px;
				font-size: 16px;
			}

			.mui-preview-image {
				display: none;
				-webkit-animation-duration: 0.5s;
				animation-duration: 0.5s;
				-webkit-animation-fill-mode: both;
				animation-fill-mode: both;
			}

			.mui-preview-image.mui-preview-in {
				-webkit-animation-name: fadeIn;
				animation-name: fadeIn;
			}

			.mui-preview-image.mui-preview-out {
				background: none;
				-webkit-animation-name: fadeOut;
				animation-name: fadeOut;
			}

			.mui-preview-image.mui-preview-out .mui-preview-header,
			.mui-preview-image.mui-preview-out .mui-preview-footer {
				display: none;
			}

			.mui-zoom-scroller {
				position: absolute;
				display: -webkit-box;
				display: -webkit-flex;
				display: flex;
				-webkit-box-align: center;
				-webkit-align-items: center;
				align-items: center;
				-webkit-box-pack: center;
				-webkit-justify-content: center;
				justify-content: center;
				left: 0;
				right: 0;
				bottom: 0;
				top: 0;
				width: 100%;
				height: 100%;
				margin: 0;
				-webkit-backface-visibility: hidden;
			}

			.mui-zoom {
				-webkit-transform-style: preserve-3d;
				transform-style: preserve-3d;
			}

			.mui-slider .mui-slider-group .mui-slider-item img {
				width: auto;
				height: auto;
				max-width: 100%;
				max-height: 100%;
			}

			.mui-android-4-1 .mui-slider .mui-slider-group .mui-slider-item img {
				width: 100%;
			}

			.mui-android-4-1 .mui-slider.mui-preview-image .mui-slider-group .mui-slider-item {
				display: inline-table;
			}

			.mui-android-4-1 .mui-slider.mui-preview-image .mui-zoom-scroller img {
				display: table-cell;
				vertical-align: middle;
			}

			.mui-preview-loading {
				position: absolute;
				width: 100%;
				height: 100%;
				top: 0;
				left: 0;
				display: none;
			}

			.mui-preview-loading.mui-active {
				display: block;
			}

			.mui-preview-loading .mui-spinner-white {
				position: absolute;
				top: 50%;
				left: 50%;
				margin-left: -25px;
				margin-top: -25px;
				height: 50px;
				width: 50px;
			}

			.mui-preview-image img.mui-transitioning {
				-webkit-transition: -webkit-transform 0.5s ease, opacity 0.5s ease;
				transition: transform 0.5s ease, opacity 0.5s ease;
			}

			@-webkit-keyframes fadeIn {
				0% {
					opacity: 0;
				}

				100% {
					opacity: 1;
				}
			}

			@keyframes fadeIn {
				0% {
					opacity: 0;
				}

				100% {
					opacity: 1;
				}
			}

			@-webkit-keyframes fadeOut {
				0% {
					opacity: 1;
				}

				100% {
					opacity: 0;
				}
			}

			@keyframes fadeOut {
				0% {
					opacity: 1;
				}

				100% {
					opacity: 0;
				}
			}

			p img {
				max-width: 100%;
				height: auto;
			}

			.mui-numbox {
				height: 26px;
			}

			.mui-numbox,
			.mui-numbox .mui-input-numbox {
				border: none !important;
			}

			.mui-numbox [class*=btn-numbox],
			.mui-numbox [class*=numbox-btn] {
				background-color: #e0e0e0;
			}

			.slider-num {
				position: absolute;
				bottom: 10px;
				right: 10px;
				background-color: #a7a7a7;
				color: #fff;
				border-radius: 15px;
				padding: 4px 6px;
			}

			.info {
				padding: 10px;
				padding-bottom: 0;
				background-color: #fff;
				margin-bottom: 10px;
			}

			.info .title {
				font-weight: 600;
			}

			.mui-table-view:after,
			.mui-table-view:before {
				height: 0;
			}

			.pj {
				margin-bottom: 10px;
			}

			.pj .top {
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 40px;
				padding: 0 10px;
				background-color: #fff;
				margin-bottom: 1px;
			}

			.pj .top .left {
				font-size: 15px;
			}

			.pj .top .right {
				font-size: 14px;
				color: #9b9b9b;
			}

			.pj .bottom {
				padding: 10px;
				padding-bottom: 0;
				background-color: #fff;
			}

			.pj .bottom .pj-tag {
				display: flex;
				flex-wrap: wrap;
			}

			.pj .bottom .pj-tag .pj-tag-item {
				background-color: #fdefee;
				color: #6d6d6f;
				font-weight: 600;
				font-size: 15px;
				border-radius: 6px;
				padding: 6px;
				margin-right: 10px;
				margin-bottom: 10px;
			}

			.shop-info {
				background-color: #fff;
				padding: 10px;
			}

			.shop-info .top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 20px;
			}

			.shop-info .top .left {
				display: flex;
				align-items: center;
			}

			.shop-info .top img {
				width: 50px;
				height: 50px;
				margin-right: 10px;
				border-radius: 4px;
			}

			.shop-info .top .mid {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
			}

			.shop-info .top .mid .desc {
				margin-top: 10px;
				font-size: 14px;
				color: #58595d;
			}

			.shop-info .bottom {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 10px;
				border-radius: 8px;
				background-color: #dfe9ea;
			}

			.shop-info .bottom .left {
				font-weight: 700;
				font-size: 15px;
			}

			.shop-info .bottom .right {
				display: flex;
				align-items: center;
			}

			.shop-info .bottom .right .desc {
				font-size: 15px;
				color: #565a5b;
			}

			.footer {
				position: fixed;
				bottom: 0;
				left: 0;
				right: 0;
				height: 60px;
				background-color: #fff;
				display: flex;

			}

			.help {
				display: flex;
				justify-content: space-around;
				flex: 1;
			}

			.help-item {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				font-size: 14px;
			}

			.help-item img {
				margin-bottom: 10px;
			}

			.shopping {
				flex: 2;
				background-color: #e02e24;
				color: #fff;
				font-weight: 600;
				font-size: 20px;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.shopping span {
				font-size: 14px;
			}

			.gettop {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				width: 50px;
				height: 50px;
				background-color: #000;
				position: fixed;
				right: 10px;
				bottom: 80px;
				font-size: 15px;
				background-color: #fff;
				border-radius: 50%;
				opacity: 0;
			}

			.popover-content {
				background-color: #f4f4f4;
			}

			.popover-content .top .ls-item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				background-color: #fff;
				height: 50px;
				margin-bottom: 1px;
				padding: 0 10px;
			}

			.popover-content .top .ls-item div {
				margin-left: 10px;
			}


			.popover-content .top .ls-item .left {
				display: flex;
				align-items: center;
			}

			.popover-content .top .ls-item .left div {
				font-size: 15px;
				font-weight: 530;
			}

			.popover-content .bottom {
				padding-left: 10px;
				background-color: #fff;

			}

			.popover-content .bottom .info {
				display: flex;
				align-items: center;
				padding-bottom: 10px;
				border-bottom: 1px solid #ebebeb;
			}

			.popover-content .bottom .info img {
				width: 100px;
				height: 100px;
				margin-right: 10px;
			}


			.popover-content .bottom .info .desc {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
			}

			.popover-content .bottom .info .desc .top {
				margin-bottom: 20px;
			}


			.popover-content .bottom .info .price {
				font-size: 22px;
				color: #d83129;
			}

			.popover-content .bottom .info .wup {
				font-size: 14px;
			}

			.container {}

			.container .title {
				margin-bottom: 10px;
			}

			.tags {
				display: flex;
				flex-wrap: wrap;
				margin-bottom: 20px;
				max-height: 140px;
				overflow-y: scroll;
				padding-top: 10px;
			}

			.tags .active {
				color: #e02e24;
				border: 1px solid #e02e24;
				background-color: transparent;
			}

			.tag-item {
				position: relative;
				border-radius: 4px;
				background-color: #f2f2f2;
				font-size: 15px;
				padding: 6px;
				margin-right: 10px;
				margin-bottom: 12px;
				font-weight: 600;
			}

			.tag-item .export {
				color: #a7a7a7;
			}

			.tag-item .badge {
				position: absolute;
				left: 0;
				top: -8px;
				font-size: 10px;
				background-color: #e02e24;
			}

			.tag-item div {
				max-width: 300px;
			}

			.pay {
				display: flex;
				align-items: center;
				justify-content: center;
				height: 50px;
				color: #fff;
				background-color: #e02e24;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav mui-bar-transparent" data-top='0' data-offset='150' data-duration='16'
			data-scrollby=".mui-scroll-wrapper">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">商品详情</h1>
		</header>
		<div class="mui-content" style="padding-bottom: 60px;padding-top: 0;">
			<div id="slider" class="mui-slider">
				<div id="sl" class="mui-slider-group">

				</div>
				<span class="slider-num"><span id="target"></span>/<span id="count"></span></span>
			</div>

			<div class="info">
				<div id="tle" class="title mui-ellipsis-2">

				</div>
				<ul class="mui-table-view">
					<li class="mui-table-view-cell">
						<a class="mui-navigate-right mui-ellipsis"
							style="padding-left: 0;padding-right: 0;font-size: 15px;">
							<div id="service" class="mui-ellipsis" style="width: 320px;">

							</div>
						</a>
					</li>
				</ul>
			</div>

			<div class="pj">
				<div class="top">
					<div class="left">
						该商品所属店铺评价(47)
					</div>
					<div class="right">
						查看更多
						<span class="mui-icon mui-icon-arrowright" style="font-size: 15px;"></span>
					</div>
				</div>
				<div class="bottom">
					<div class="pj-tag">
						<div class="pj-tag-item">
							好用(15)
						</div>
						<div class="pj-tag-item">
							好用(15)
						</div>
						<div class="pj-tag-item">
							好用(15)
						</div>
						<div class="pj-tag-item">
							好用(15)
						</div>
						<div class="pj-tag-item">
							好用(15)
						</div>
					</div>
				</div>
			</div>

			<div id="shopInfo" class="shop-info">
				<div class="top">
					<div class="left">

					</div>
					<button type="button" class="mui-btn mui-btn-outlined">进店</button>
				</div>
				<div class="bottom">
					<div class="left">
						店铺保障
					</div>
					<div class="right">
						<div class="desc">

						</div>
						<span class="mui-icon mui-icon-arrowright" style="font-size: 15px;"></span>
					</div>
				</div>
			</div>

			<div class="gettop">
				<span class="mui-icon mui-icon-extra-top"></span>
				<div>顶部</div>
			</div>

			<div id="sheet1" class="mui-popover mui-popover-bottom mui-popover-action ">
				<!-- 可选择菜单 -->
				<div class="popover-content">
					<div class="top">
						<div class="ls">
							<div class="ls-item">
								<div class="left">
									<span class="mui-icon mui-icon-location"></span>
									<div id="address" class="mui-ellipsis" style="max-width: 280px;"></div>
								</div>
								<span class="mui-icon mui-icon-arrowright"></span>
							</div>
							<div class="ls-item">
								<div class="left">
									<span class="mui-icon mui-icon-email"></span>
									<div>普通配送(10元)(满99免运费)</div>
								</div>
								<span class="mui-icon mui-icon-arrowright"></span>
							</div>
						</div>
					</div>

					<div class="bottom">
						<div class="info">
							<img src="images/cbd.jpg" alt="" />
							<div class="desc">
								<div class="top">
									<div class="price">

									</div>
									<div class="wup">
										已选：${data.items[0].sku_name}
									</div>
								</div>
								<div id="size-container">

								</div>

							</div>
						</div>
						<div class="container">
							<div class="title">
								容量
							</div>
							<div id="rl" class="tags">

							</div>


							<div class="title">
								服务
							</div>
							<div id="serviceList" class="tags" style="margin-bottom: 0;">

							</div>

						</div>
					</div>

					<div class="pay">

					</div>
				</div>
			</div>
		</div>
		<footer class="footer">
			<div class="help">
				<div class="help-item">
					<span class="mui-icon mui-icon-chatbubble"></span>
					<div class="name">
						店铺
					</div>
				</div>
				<div class="help-item">
					<span class="mui-icon mui-icon-chatbubble 
				"></span>
					<div class="name">
						店铺
					</div>
				</div>
				<div class="help-item">
					<span class="mui-icon mui-icon-chatbubble
								"></span>
					<div class="name">
						店铺
					</div>
				</div>
			</div>
			<div id="openPopover" class="shopping">
				<div class="desc">
					单价
				</div>
				<div class="price">

				</div>
			</div>
		</footer>



		<script src="js/mui.min.js"></script>
		<script src="js/mui.zoom.js"></script>
		<script src="js/mui.previewimage.js"></script>
		<script src="libs/app.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			mui.init()

			document.getElementById('address').addEventListener('tap', function() {
				mui.openWindow('shdz.html', 'shdz.html', {})
			})

			function setMaxSum(sum) {
				document.getElementById("size-container").innerHTML = `<div id="size" class="mui-numbox" data-numbox-step='1' data-numbox-min='1' data-numbox-max="${sum}">
										<button id="jianjian" class="mui-btn mui-btn-numbox-minus" type="button">-</button>
										<input disabled class="mui-input-numbox" type="number" />
										<button id="add" class="mui-btn mui-btn-numbox-plus" type="button">+</button>
									</div>`
				mui("#size").numbox()
			}

			function add() {
				var size = mui('#size').numbox().getValue()
				console.log(size);
				quantity = size
				sumPayment = parseInt(size) * defaulPrice
				console.log(sumPayment);
				pay.innerHTML = `马上抢，仅${sumPayment}元`
				infoDescTopPrice.innerHTML = `￥${sumPayment}`
				// shoppingPrice.innerHTML = `￥${sumPayment}`
			}

			function jianjian() {
				var size = mui('#size').numbox().getValue()
				console.log(size);
				quantity = size
				sumPayment = parseInt(size) * defaulPrice
				console.log(sumPayment);
				pay.innerHTML = `马上抢，仅${sumPayment}元`
				infoDescTopPrice.innerHTML = `￥${sumPayment}`
				// shoppingPrice.innerHTML = `￥${sumPayment}`
			}


			function triggerSku(index) {
				slideTaget = 1
				defaulPrice = 0
				sumPayment = 0
				var data = items[index]

				sku_id = data.id
				var images = data.images
				var price = data.price
				defaulPrice = price
				var imgs = images.split(',')

				setMaxSum(data.stock)

				document.getElementById('add').addEventListener('tap', add)

				document.getElementById('jianjian').addEventListener('tap', jianjian)


				var s = ''
				for (let i = 0; i < imgs.length; i++) {
					s += `<div class="mui-slider-item">
							<a href="#">
								<img data-preview-src="" data-preview-group="1" src="${resUrl + imgs[i]}" style="width:100%;height:100%">
							</a>
						</div>`
				}

				shoppingPrice.innerHTML = `￥${price}`
				pay.innerHTML = `马上抢，仅${price}元`
				document.querySelector("#sheet1 .info>img").src = `${resUrl+imgs[0]}`
				infoDescTopPrice.innerHTML = `￥${price}`
				infoDescTopWup.innerHTML = `已选：${data.sku_name}`
				document.getElementById("sl").innerHTML = s
				tagert.innerText = slideTaget
				document.getElementById("count").innerText = imgs.length
			}

			var id = localStorage.getItem('detailid')

			var tagert = document.getElementById("target")
			var slideTaget = 1
			var defaulPrice = 0
			var sumPayment = 0
			var items = []
			var tagActiveIndex = 0
			var serviceListtagActiveIndex = 0
			var address_id = 0
			var sku_id = 0
			var quantity = 0

			var pay = document.querySelector("#sheet1 .pay")
			var infoDescTopPrice = document.querySelector("#sheet1 .info>.desc>.top>.price")
			var infoDescTopWup = document.querySelector("#sheet1 .info>.desc>.top>.wup")
			var shoppingPrice = document.querySelector(".shopping .price")
			var serviceList = document.getElementById("serviceList")

			if (id) {
				post('/api/product/detail', {
					id
				}).then(res => {
					console.log(res);
					if (res.code == 1) {
						var data = res.data
						var s = ''

						document.querySelector("#shopInfo>.top>.left").innerHTML = `<img src="${resUrl+data.shop_info.image}" alt="" />
						<div class="mid">
							<div class="mui-h4">${data.shop_info.name}</div>
							<div class="desc">
								已拼xxx件|xxxx|粉丝xxx
							</div>
						</div>`


						if (data.items.length > 0) {
							items = data.items
							var images = data.items[0].images
							var price = data.items[0].price
							defaulPrice = price
							sku_id = data.items[0].id
							var imgs = images.split(',')
							document.getElementById("tle").innerText = data.items[0].sku_name

							setMaxSum(data.items[0].stock)

							document.getElementById('add').addEventListener('tap', add)

							document.getElementById('jianjian').addEventListener('tap', jianjian)

							for (let i = 0; i < imgs.length; i++) {
								s += `<div class="mui-slider-item">
										<a href="#">
											<img data-preview-src="" data-preview-group="1" src="${resUrl + imgs[i]}" style="width:100%;height:100%">
										</a>
									</div>`
							}
							var s1 = ''
							data.items.forEach((e, index) => {
								if (e.stock <= 100) {
									s1 += `<div data-id="${index}" class="tag-item ${index==0?'active':''}">
										<span class="mui-badge mui-badge-danger badge" style="">最后${e.stock}件</span>
										<div class="mui-ellipsis">${e.sku_name}</div>
									</div>`
								} else {
									s1 += `<div data-id="${index}" class="tag-item ${index==0?'active':''}"">
										<div class="mui-ellipsis">${e.sku_name}</div>
									</div>`
								}

							})

							shoppingPrice.innerHTML = `￥${price}`
							pay.innerHTML = `马上抢，仅${price}元`
							document.querySelector("#sheet1 .info>img").src = `${resUrl+imgs[0]}`
							infoDescTopPrice.innerHTML = `￥${price}`
							infoDescTopWup.innerHTML = `已选：${data.items[0].sku_name}`
							document.getElementById("rl").innerHTML = s1
							document.getElementById("sl").innerHTML = s
							tagert.innerText = slideTaget
							document.getElementById("count").innerText = imgs.length

							var rlTagItems = document.querySelectorAll('#rl>.tag-item')
							rlTagItems.forEach((e, i) => {
								e.addEventListener('tap', function() {
									var id = this.getAttribute('data-id')
									if (id == tagActiveIndex) return
									rlTagItems[tagActiveIndex].classList.remove('active')
									tagActiveIndex = id
									e.classList.add('active')
									triggerSku(id)
								})
							})

							mui('#slider').slider({})
							mui.previewImage();
							document.querySelector('#slider').addEventListener('slide', function(event) {
								//注意slideNumber是从0开始的；
								tagert.innerText = event.detail.slideNumber + 1
							});
						}

					} else {
						mui.toast(res.msg)
					}

				})

				post('/api/service/list', {
					"product_id": id
				}).then(res => {
					console.log(res);
					var data = res.data
					var s = ''
					var s1 = ''
					if (data.length > 0) {
						data.forEach((e, i) => {
							s += `${e.name} `
							s1 += `<div data-id="${i}" class="tag-item ${i==0?'active':''}">
									<div class="mui-ellipsis">${e.name}<span class="export">（商家赠送）</span></div>
								</div>`
						})
					} else {
						s = '暂无数据'
					}

					document.getElementById("service").innerText = s
					serviceList.innerHTML = s1
					var serviceListTagItems = document.querySelectorAll('#serviceList>.tag-item')
					serviceListTagItems.forEach((e, i) => {
						e.addEventListener('tap', function() {
							var id = this.getAttribute('data-id')
							if (id == serviceListtagActiveIndex) return
							serviceListTagItems[serviceListtagActiveIndex].classList.remove('active')
							serviceListtagActiveIndex = id
							e.classList.add('active')
						})
					})
					document.querySelector("#shopInfo>.bottom>.right>.desc").innerText = s
				})

				post('/api/address/getdefault').then(res => {
					console.log(res);
					var data = res.data
					address_id = data.id
					// {
					//         "id": 2,
					//         "user_id": 5,
					//         "consignee": "徐乾坤",
					//         "mobile": "19852675088",
					//         "province": "江苏省",
					//         "city": "常州市",
					//         "district": "武进区",
					//         "address": "红莲路 88号",
					//         "is_default": 1,
					//         "deletetime": null
					//     }
					var address =
						`${data.consignee},${data.mobile},${data.province}${data.city}${data.district}${data.address}`
					document.getElementById("address").innerText = address
				})
			}


			document.getElementById('openPopover').addEventListener('tap', function() {
				mui('#sheet1').popover('show')
			})

			pay.addEventListener('tap', function() {
				var param = {
					"address_id": address_id,
					"items": [{
						"product_id": id,
						"sku_id": sku_id,
						"quantity": quantity
					}]
				}
				post('/api/order/create', param).then(res => {
					console.log(res);
					if (res.code) {
						var data = res.data
						localStorage.setItem('orderNo', data.order_no)
						mui.openWindow('shop_ok.html', 'shop_ok.html', {
							orderNo: data.order_no
						})
					}
				})
			})

			window.addEventListener('updateAddress', function(e) {
				var id = e.detail.id
				address_id = id
				document.getElementById("address").innerText = address
			})
		</script>
	</body>

</html>